<template>
	<view class="" style="width: 100%;" @tap="open">
		<u-input v-model="value1" readonly type="select" :placeholder="placeholders" />
		<!-- 开始时间 -->
		<u-datetime-picker :minDate="-2209017943000" :maxDate="4102416000000" @cancel="show=false" :show="show"
			@confirm="optionClick" mode="year-month"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		dictSect,
		dictFuns
	} from "@/util/dictionary.js"
	export default {
		props: ["data", "value", "keys", "placeholder"],
		name: "TimeSelectMonth",
		data() {
			return {
				show: false,
				value1: "",
				options: [],
				placeholders: "请选择",
			}
		},
		watch: {
			placeholders: {
				handler: function(newValue) {
					// console.log("监听keys",newValue);
					this.placeholders = newValue
				},
				immediate: true,
				deep: true,
			},
			data: {
				handler: function(newValue) {
					// console.log("监听data",newValue);
				},
				immediate: true,
				deep: true,
			},
			value: {
				handler: function(newValue) {
					// console.log("监听value",newValue);
					if(newValue){
						this.value1 = newValue.slice(0,7)
					}else{
						this.value1 = ""
					}
					
					// this.value1 = this.dictFunsF(newValue, this.dict)
				},
				immediate: true,
				deep: true,
			},
			dict: {
				handler: function(newValue) {
					// console.log("监听dict",newValue);
					this.dictfun(newValue)
				},
				immediate: true,
				deep: true,
			},

		},
		methods: {
			open() {
				this.show = true
				setTimeout(() => {
					uni.hideKeyboard()
				}, 10)
			},
			dictfun(value) {
				this.options = []
				this.options.push(dictSect(value))
				// console.log("下拉数据", this.options);
			},
			dictFunsF(value, res) {
				return dictFuns(value, res)
			},
			optionClick(e) {
				console.log("点击选中", e);
				this.$emit('mySelectclick', {
					value: this.timestampToTime(e.value),
					key: this.keys
				})
				this.show = false
			},
			timestampToTime(timestamp) {
				// 时间戳为10位需*1000，时间戳为13位不需乘1000
				// var date = new Date(timestamp * 1000);
				var date = new Date(timestamp);
				let Y = date.getFullYear() + "-"; //年
				let M =
					(date.getMonth() + 1 < 10 ?
						"0" + (date.getMonth() + 1) :
						date.getMonth() + 1) + "-"; //
				let D =
					(date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "; //日
				let h =
					(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"; //时
				let m =
					(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
					":"; //分
				let s =
					date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); //秒
				return Y + M + D + h + m + s;
			},
		}
	}
</script>

<style lang="scss">
</style>
